$(function(){

    $.fn.dialog=function(options){
        if(typeof(options)=="object"){
            var opts={
                title:"",
                btnName:"确定",
                btnBind:null
            };
            for(var prop in opts){
                opts[prop]=options[prop]||opts[prop];
            }
            var html='  <div class="modal fade">\n' +
                '        <div class="modal-dialog">\n' +
                '            <div class="modal-content">\n' +
                '                <div class="modal-header">\n' +
                '                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>\n' +
                '                    <h4 class="modal-title"></h4>\n' +
                '                </div>\n' +
                '                <div class="modal-body">\n' +
                '                </div>\n' +
                '                <div class="modal-footer">\n' +
                '                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>\n' +
                '                    <button type="button" class="btn btn-primary">确定</button>\n' +
                '                </div>\n' +
                '            </div><!-- /.modal-content -->\n' +
                '        </div><!-- /.modal-dialog -->\n' +
                '    </div><!-- /.modal -->';
            var $modal=$(html);
            $modal.find(".modal-title").html(opts.title);
            $modal.find(".modal-body").append(this);
            var $confim=$modal.find("button:last");
            if(opts.btnBind==null){
                $confim.remove();
            }else{
                $confim.html(opts.btnName);
                $confim.off("click").on("click",opts.btnBind);
            }
            $modal.appendTo("body");
        }else{
            if("open"==options){
                this.parents(".modal").modal("show");
            }
            if("close"==options){
                this.parents(".modal").modal("hide");
            }
        }
    }




});